/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import DTO.DatabaseDTO;
import GUI.Helper;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

/**
 *
 * @author TrongKhoa
 */
public class DatabaseDAO
{

    private String ServerPath;

    public DatabaseDTO CreateNewDatabase(String databaseName)
    {
        Document doc = XmlHelper.CreateDocument("Database");
        Element root = doc.getDocumentElement();
        root.setAttribute("Name", databaseName);

        String databaseFile = String.format("%s%s.xml", ServerPath, databaseName);
        XmlHelper.writeXmlToFile(databaseFile, doc);
        return new DatabaseDTO(doc);
    }

    public String getServerPath()
    {
        return ServerPath;
    }

    public void setServerPath(String ServerPath)
    {
        this.ServerPath = ServerPath;
    }

    public DatabaseDTO LoadExistingDatabase(String path)
    {
        
        Document doc = null;
        try
        {
            doc = XmlHelper.Parse(path);
        }
        catch (Exception ex)
        {
            Helper.Print("Không parse được file database");
        }
        Element root = doc.getDocumentElement();
        return new DatabaseDTO(doc);
    }
}
